/* 
 * A jQuery photogallery plugin
 * uphgall
 * version: 0.9
 * https://code.google.com/p/uphgall
 * Copyright (c) 2012 Victor Grusha
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
var uphgall = function(params){
var
sizes = {
	t:		[32,48,64,72,104,144,150,160],
	i:		[94,110,128,200,220,288,320,400,512,576,640,720,800,912,1024,1152,1280,1440,1600]
},
gal = {
	Cache:		true,
	User:		'',
	Album:		'',
	AuthKey:	'',
	Access:		'',
	Query:		'',
	Tag:		'',
	Location:	'',
	StartIndex:	'',
	MaxResults:	'',
	PublishedMin:	'',
	PublishedMax:	'',
	UpdatedMin:	'',
	UpdatedMax:	'',
	Fields:		'fields='+'title,subtitle,link[@rel="alternate"],updated,author,entry(title,link[@rel="alternate"],content,summary,published,updated,media:group(media:keywords),gphoto:width,gphoto:height)'+'&',
	ValidSizes:	1,//-2<=x<=1
	
	ImgSize:{
		t:{
			real:{
				h:72,
				w:72
			},
			valid:{
				h:72,
				w:72
			},
			c:'-c'
		},
		i:{
			real:{
				h:512,
				w:512
			},
			valid:{
				h:512,
				w:512
			}
		}
	},
	
	GalleryId:	' #uphgall',
	
	AlbumId:	' .album',
	AuthorId:	' .author',
	CanvasId:	' .canvas',
	ThumbsId:	' .thumbs',
	
	ImageId:	' .img',
	NameId:		' .name',
	LinkId:		' .link',
	DescriptionId:	' .description',
	TagsId:		' .tags',
	PublishedId:	' .published',
	UpdatedId:	' .updated',
	IndexId:	' .index',
	QuantityId:	' .quantity',
	
	SlideShowId:	' .slideshow',
	PlayId:		' .play',
	StopId:		' .stop',
	
	FirstId:	' .first',
	PrevId:		' .prev',
	NextId:		' .next',
	LastId:		' .last',
	CurrentId:	' .current',
	
	PaginationId:	' .pagination',
	PSpacerId:	' .spacer',
	PPageId:	' .page',
	
	NavigationId:	' .navigation',
	
	ThumbsCapacity:	0,
	ThumbsPages:	null,
	IndexC:		0,
	IndexP:		1,
	ThreadsThumbs:	16,
	ThreadsCanvas:	2,
	PreloadQuantity:[1,3],
	PreloadOrder:	3,
	
	Transition:{
		Time:	200
	},
	
	SlideShow:{
		Timer:	null,
		Time:	5000,
		Plays:	false
	},
	
	DateC:		null,
	DateT:		null,
	info:		{}

},
imgs = []
//functions
var
request = function(){
	if(!checkparams()) return false
	$.ajax({
		url:		'https://picasaweb.google.com/data/feed/api'+gal.User+gal.Album+'?'+gal.AuthKey+gal.Access+gal.Query+gal.Tag+gal.Location+
				gal.StartIndex+gal.MaxResults+gal.PublishedMin+gal.PublishedMax+gal.UpdatedMin+gal.UpdatedMax+gal.Fields+
				'alt=json&kind=photo',
		cache:		gal.Cache,
		dataType:	'jsonp',
		error:		function(jqXHR, textStatus, errorThrown){alert('Error:'+textStatus)},
		success:	function(data){
					var i,d,link
					gal.info={
						link:	(data.feed.link)?data.feed.link[0].href:'',
						title:	data.feed.title.$t,
						desc:	(data.feed.subtitle)?data.feed.subtitle.$t:'',
						upd:	'<span class="date">'+data.feed.updated.$t.substring(0,10)+'</span><span class="time">'+data.feed.updated.$t.substring(11,16)+'</span>',
						author:	{
							link:	(data.feed.author)?data.feed.author[0].uri.$t:'',
							name:	(data.feed.author)?data.feed.author[0].name.$t:''
						}
					}
					if(!$.isEmptyObject(data.feed.entry)){
						for(i=0;i<data.feed.entry.length;i++){
							d=data.feed.entry[i]
							link=d.content.src
							imgs[i]={
								link:	link.slice(0,link.lastIndexOf('/')+1),
								name:	link.slice(link.lastIndexOf('/')+1),
								title:	d.title.$t,
								href:	d.link[0].href,
								desc:	d.summary.$t,
								pub:	'<span class="date">'+d.published.$t.substring(0,10)+'</span><span class="time">'+d.published.$t.substring(11,16)+'</span>',
								upd:	'<span class="date">'+d.updated.$t.substring(0,10)+'</span><span class="time">'+d.updated.$t.substring(11,16)+'</span>',
								tags:	(d.media$group.media$keywords.$t)?d.media$group.media$keywords.$t:'',
								w:	d.gphoto$width.$t,
								h:	d.gphoto$height.$t,
								ratio:	d.gphoto$width.$t/d.gphoto$height.$t
							}
						}
						calcimgsizes()
						build()
					}
				},
		complete:	function(jqXHR, textStatus){}	
	})//end ajax
	return true
},//end function request
calcimgsizes = function(){
	var	i,
		GalleryRatio={
			i:gal.ImgSize.i.real.w/gal.ImgSize.i.real.h,
			t:gal.ImgSize.t.real.w/gal.ImgSize.t.real.h
		},
		individualsize = function(type){
			var 	result,
				calcsize = function(side){
					var	j,
						targetsize=(side=='h')?gal.ImgSize[type].real[side]*imgs[i].ratio:gal.ImgSize[type].real[side]/imgs[i].ratio
					for(j=sizes[type].length;j>0;j--)
						if(targetsize>sizes[type][j])
							break
					return sizes[type][j]
				}
			if(type=='t'&&gal.ImgSize.t.c=='-c')
				result={l:'s',s:Math.min(gal.ImgSize.t.valid.h,gal.ImgSize.t.valid.w)}
			else if(gal.ValidSizes<0)
				result=(imgs[i].ratio>GalleryRatio[type])?{l:'w',s:w}:{l:'h',s:h}
			else if(imgs[i].ratio>GalleryRatio[type])
				result={l:'s',s:(imgs[i].ratio>=1)?gal.ImgSize[type].valid.w:calcsize('w')}
			else
				result={l:'s',s:(imgs[i].ratio<=1)?gal.ImgSize[type].valid.h:calcsize('h')}
				
			if(result.l=='s'&&type=='i')
				if(result.s>Math.max(imgs[i].w,imgs[i].h))
					result={l:'d',s:''}
			
			return result
		}
	for(i=0;i<imgs.length;i++){
		imgs[i].isize=individualsize('i')
		imgs[i].tsize=individualsize('t')
	}
},//end function calcimgsizes
calccanvsize = function(bsize,type){
	var i,tsize
	bsize=Math.floor(bsize)
	if(bsize<=sizes[type][0]){
		tsize = sizes[type][0]
	}else if(bsize>=sizes[type][sizes[type].length-1]){
		tsize = sizes[type][sizes[type].length-1]//костыль для HD
	}else if(Math.abs(gal.ValidSizes)==1){
		for(i=1;i<sizes[type].length;i++)
			if(bsize<sizes[type][i]){
				tsize = sizes[type][i-1]
				break
			}else if(bsize==sizes[type][i]){
				tsize = sizes[type][i]
				break
			}
	}else{
		tsize = bsize
	}
	return tsize
},//end function calccanvsize
select=function(tag,field,number){
	var	i,t='',
		$o=$(gal.GalleryId+gal[tag]+gal[field]),
		tags=['AlbumId','AuthorId','CanvasId','ThumbsId']
	for(i=0;i<tags.length;i++)
		if(tags[i]!=tag)
			t+=gal[tag]+gal[tags[i]]+gal[field]+','
	return	(typeof(number)=='number')
		? $o.eq(number).not(t.substring(0,t.length-1))
		: $o.not(t.substring(0,t.length-1))
},//end function select
build = function(){
	//index
	$(gal.GalleryId+gal.QuantityId).text(imgs.length)
	//album
	select('AlbumId','LinkId').attr('href',gal.info.link)
	select('AlbumId','NameId').text(gal.info.title)
	select('AlbumId','DescriptionId').text(gal.info.desc)
	select('AlbumId','UpdatedId').append(gal.info.upd)
	//author
	select('AuthorId','LinkId').attr('href',gal.info.author.link)
	select('AuthorId','NameId').text(gal.info.author.name)
	
	if($(gal.GalleryId+gal.ThumbsId+'>li').length){
		var	i,
			UlLi=$.trim($(gal.GalleryId+gal.ThumbsId).clone().children('li').hide().end().html()),
			Thumbs=''
		for(i=0;i<imgs.length;i++)
			Thumbs += UlLi
		if(gal.ThumbsCapacity<1)
			gal.ThumbsCapacity=Math.floor($(gal.GalleryId+gal.ThumbsId).width()/$(gal.GalleryId+gal.ThumbsId+'>li').outerWidth(true))*Math.floor($(gal.GalleryId+gal.ThumbsId).height()/$(gal.GalleryId+gal.ThumbsId+'>li').outerHeight(true))
		if(!gal.ThumbsCapacity>0)
			gal.ThumbsCapacity=10000
		if(gal.ThumbsCapacity>0){
			gal.ThumbsPages=Math.ceil(imgs.length/gal.ThumbsCapacity)
			gal.IndexP=Math.ceil((gal.IndexC+1)/gal.ThumbsCapacity)
			$(gal.GalleryId+gal.ThumbsId).html(Thumbs)
		}
		if(gal.ThumbsPages>1){
			$(gal.GalleryId+gal.PaginationId).each(
				function(){
					if($(this).find(gal.PPageId).length){
						var Page, Pages = ''
						if($(this).find(gal.PPageId).is('li'))
							Page = $(this).find(gal.PPageId).clone().wrap('<ul></ul>')
						else
							Page = $(this).find(gal.PPageId).parents('li').clone().wrap('<ul></ul>')
						for(var i=1;i<1+gal.ThumbsPages;i++)
							Pages += Page.parent().find(gal.PPageId).text(i).end().html()
						$(this).children('li'+gal.PPageId.slice(1)+', li:has('+gal.PPageId+')').replaceWith(Pages)
					}
				}
			)
		}
	}
	if(gal.ThumbsPages<2)
		$(gal.GalleryId+gal.PaginationId).css('visibility','hidden')
	if(gal.SlideShow.Plays)
		$(gal.GalleryId+gal.SlideShowId).addClass(gal.PlayId.slice(2))
	else
		$(gal.GalleryId+gal.SlideShowId).addClass(gal.StopId.slice(2))
	control()
	anotherpage(gal.IndexP,true)
	if($(gal.GalleryId+gal.ThumbsId+'>li').length)
		imgload(0,true,false)
	else
		imgload(gal.IndexC,true)
	return true
},//end function build
anotherpage = function(index,force){
	force=force||false
	switch (index){
		case 'f':
			index=1
			break
		case 'p':
			index=gal.IndexP-1
			break
		case 'n':
			index=gal.IndexP+1
			break
		case 'l':
			index=gal.ThumbsPages
			break
	}
	if(index<1)
		index=gal.ThumbsPages
	else if(index>gal.ThumbsPages)
		index=1
	if(index!=gal.IndexP||force){
		$(gal.GalleryId+gal.ThumbsId+'>li:visible').hide()
		$(gal.GalleryId+gal.ThumbsId+'>li').slice((index-1)*gal.ThumbsCapacity,index*gal.ThumbsCapacity).show()
		
		$(gal.GalleryId+gal.PaginationId+'>'+gal.CurrentId).removeClass(gal.CurrentId.slice(2))
		$(gal.GalleryId+gal.PaginationId).each(function(){
			$(this).children('li'+gal.PPageId.slice(1)+', li:has('+gal.PPageId+')').eq(index-1).addClass(gal.CurrentId.slice(2))
		})
		gal.IndexP=index
	}
},//end function anotherpage
slideshow=function(){
	imgload('n')
},//end function slideshow
slideshowcontrol=function(play){
	if(play){
		$(gal.GalleryId+gal.SlideShowId).removeClass(gal.StopId.slice(2)).addClass(gal.PlayId.slice(2))
		gal.SlideShow.Timer=setInterval(function(){slideshow()},gal.SlideShow.Time)
		gal.SlideShow.Plays=false
	}
	else{
		$(gal.GalleryId+gal.SlideShowId).removeClass(gal.PlayId.slice(2)).addClass(gal.StopId.slice(2))
		clearInterval(gal.SlideShow.Timer)
	}
},//end function slideshowcontrol
control = function(){
	var	index,
		check=function(id,e){
				return $(e).is(id+','+id+' *')
		}
	//thumbs
	$(gal.GalleryId+gal.ThumbsId).live('click',function(e){
		var temp=gal.ThumbsId+'>li'
		if($(e.target).is(temp+','+temp+' *')){
			if($(e.target).is(temp))
				index = $(e.target).index()+1
			else
				index = $(e.target).parents(temp).index()+1
			slideshowcontrol(false)
			imgload(index-1)
		}
	})
	//navigation
	$(gal.GalleryId+gal.NavigationId).live('click',function(e){
		//first
		if(check(gal.FirstId,e.target)){
			slideshowcontrol(false)
			imgload('f')
			return
		}
		//prev
		if(check(gal.PrevId,e.target)){
			imgload('p')
			slideshowcontrol(false)
			return
		}
		//next
		if(check(gal.NextId,e.target)){
			imgload('n')
			slideshowcontrol(false)
			return
		}
		//last
		if(check(gal.LastId,e.target)){
			imgload('l')
			slideshowcontrol(false)
			return
		}
	})
	//slideshow
	$(gal.GalleryId+gal.SlideShowId).live('click',function(){
		if($(this).is('.play'))
			slideshowcontrol(false)
		else if($(this).is('.stop'))
			slideshowcontrol(true)
	})
	//pagination
	$(gal.GalleryId+gal.PaginationId).live('click',function(e){
		//page
		if(check(gal.PPageId,e.target)){
			anotherpage($(e.target).index('li'+gal.PPageId.slice(1))+1)
			return
		}
		//first
		if(check(gal.FirstId,e.target)){
			anotherpage('f')
			return
		}
		//prev
		if(check(gal.PrevId,e.target)){
			anotherpage('p')
			return
		}
		//next
		if(check(gal.NextId,e.target)){
			anotherpage('n')
			return
		}
		//last
		if(check(gal.LastId,e.target)){
			anotherpage('l')
			return
		}
	})
	
	
},//end function control
imgload = function(index,force,cmode){
	force=force||false
	
	var 	temp=imgs.length-1,
		forward
	if(index=='f')index=0
	if(index=='p')index=gal.IndexC-1
	if(index=='n')index=gal.IndexC+1
	if(index=='l')index=temp
	if(index<0)index=temp
	if(index>temp)index=0
	
	if(index==gal.IndexC&&!force)
		return false
	
	forward=(index>=gal.IndexC||cmode)?true:false
	
	cmode=(typeof(cmode)=='boolean')?cmode:true
	
	var	quantity=[],
		threads,
		stack=[],
		Time = new Date().getTime(),
		i,
		k=gal.PreloadOrder,
		queue=[[],[]]
		b=[],
		a=[],
		preload = function(){
			if(cmode){
				if(Time!=gal.DateC)return false
			}else{
				if(Time!=gal.DateT)return false
			}
			if(stack.length==0)return false
			var	img = new Image(),
				current=stack.pop(),
				url=imgs[current].link+imgs[current][(cmode)?'isize':'tsize'].l+((cmode)?imgs[current].isize.s:imgs[current].tsize.s+gal.ImgSize.t.c)+'/'+imgs[current].name,
				process=(cmode)
				? function(){
					var	canvimg,
						setmetadata =  function(){
							$(gal.GalleryId+gal.IndexId).not(gal.ThumbsId+gal.IndexId).text(current+1)
							select('CanvasId','LinkId').attr('href',imgs[current].href)
							select('CanvasId','NameId').text(imgs[current].title)
							select('CanvasId','DescriptionId').text(imgs[current].desc)
							select('CanvasId','TagsId').text(imgs[current].tags)
							select('CanvasId','PublishedId').html(imgs[current].pub)
							select('CanvasId','UpdatedId').html(imgs[current].upd)
						}
					if(gal.IndexC==current){
						canvimg=select('CanvasId','ImageId')
						if(canvimg.length){
							canvimg
							.fadeTo(gal.Transition.Time,0,
								function(){
									$(this).css('visibility','hidden').attr('src',url)
									setmetadata()
									$(this).css('visibility','visible').stop(true).fadeTo(gal.Transition.Time,1)
									if(gal.SlideShow.Plays){
										slideshowcontrol(true)
									}
								}
							)
						}else
							setmetadata()
						$(gal.GalleryId+gal.ThumbsId+gal.CurrentId).removeClass(gal.CurrentId.slice(2))
						$(gal.GalleryId+gal.ThumbsId+'>li').eq(current).addClass(gal.CurrentId.slice(2))
					}
					if(stack.length>0)preload()
				}
				: function(){
					$(gal.GalleryId+gal.ThumbsId+'>li').eq(current).find(gal.ImageId).attr('src',url)
					
					$(gal.GalleryId+gal.ThumbsId+gal.IndexId).eq(current).text(current+1)
					select('ThumbsId','LinkId',current).attr('href',imgs[current].href)
					select('ThumbsId','NameId',current).text(imgs[current].title)
					select('ThumbsId','DescriptionId',current).text(imgs[current].desc)
					select('ThumbsId','TagsId',current).text(imgs[current].tags)
					select('ThumbsId','PublishedId',current).html(imgs[current].pub)
					select('ThumbsId','UpdatedId',current).html(imgs[current].upd)
					
					if(stack.length==0&&temp){
						temp=false
						imgload(gal.IndexC,true)
					}
					if(stack.length>0)preload()
				},
				ifimg = function(){
					$(img).load(function(){process()}).attr('src',url)
				},
				processmode=((cmode)?$(gal.GalleryId+gal.CanvasId+gal.ImageId).length:$(gal.GalleryId+gal.ThumbsId+gal.ImageId).length)?ifimg:process
			processmode()
			return true
		}//end function imgload->preload
	if(cmode)
		anotherpage(Math.ceil((index+1)/gal.ThumbsCapacity))
	
	quantity=(cmode)?gal.PreloadQuantity:[0,temp]
	if(!forward)quantity.reverse()
	threads=(cmode)?gal.ThreadsCanvas:gal.ThreadsThumbs
	
	if(cmode){
		if(quantity[0]>Math.floor(temp/k))quantity[0]=Math.floor(temp/k)
		if(quantity[1]>Math.ceil(temp/k*(k-1)))quantity[1]=Math.ceil(temp/k*(k-1))
	}

	temp=quantity[0]+quantity[1]+1
	if(threads>temp)threads=temp
	
	stack[0]=index
	for(i=0;i<quantity[0];i++)
		queue[0][i]=(index-i>0)?index-i-1:index-i-1+imgs.length
	queue[0].reverse()
	for(i=0;i<quantity[1];i++)
		queue[1][i]=(index+i+1<imgs.length)?index+i+1:index+i+1-imgs.length
	queue[1].reverse()
	if(!forward)queue.reverse()
	for(i=1;i<=quantity[0]+quantity[1];i++){
		if(i%k&&queue[1].length>0||queue[0].length==0)
			stack[i]=queue[1].pop()
		else
			stack[i]=queue[0].pop()
	}
	stack.reverse()
	if(cmode){
		gal.DateC=Time
		gal.IndexC=index
	}else{
		gal.DateT=Time
	}
	temp=true //important for preload fn!
	for(i=1;i<=threads;i++)
		preload()
	return true
},//end function imgload
checkparams = function(){
	var p,
		check=function(p){
			return params.hasOwnProperty(p)&&params[p]!==null&&params[p]!==undefined&&params[p]!==''&&!(typeof(params[p])!='string'&&!isFinite(params[p]))
		},
		ids =['GalleryId','AlbumId','AuthorId','CanvasId','ThumbsId','ImageId','NameId','LinkId','DescriptionId','TagsId','PublishedId','UpdatedId','IndexId','QuantityId','SlideShowId','PlayId','StopId','FirstId','PrevId','NextId','LastId','CurrentId','PaginationId','PSpacerId','PPageId','NavigationId']

	p='Cache'
	if(typeof(params[p])=='boolean')	gal[p]=params[p]
	
	p='User'
	if(check(p))	gal[p]='/user/'+params[p]
	p='Album'
	if(check(p))	gal[p]='/album'+(params[p].search(/\D/)>=0?'/':'id/')+params[p]
	
	for(p in ids)if(check(ids[p])){
		gal[ids[p]]=' '+params[ids[p]]
	}
	
	p='AuthKey'
	if(check(p))	gal[p]='authkey='+params[p]+'&'
	p='Access'
	if(check(p))	gal[p]='access='+params[p]+'&'
	p='Query'
	if(check(p))	gal[p]='q='+params[p]+'&'
	p='Tag'
	if(check(p))	gal[p]='tag='+params[p]+'&'
	p='Location'
	if(check(p))	gal[p]='l='+params[p]+'&'
	
	p='StartIndex'
	if($.isNumeric(params[p])&&params[p]>0)	gal[p]='start-index='+params[p]+'&'
	p='MaxResults'
	if($.isNumeric(params[p])&&params[p]>0)	gal[p]='max-results='+params[p]+'&'
	
	p='PublishedMin'
	if(check(p))	gal[p]='published-min='+params[p]+'&'
	p='PublishedMax'
	if(check(p))	gal[p]='published-max='+params[p]+'&'
	p='UpdatedMin'
	if(check(p))	gal[p]='updated-min='+params[p]+'&'
	p='UpdetedMax'
	if(check(p))	gal[p]='updated-max='+params[p]+'&'
	
	p='ValidSizes'
	if($.isNumeric(params[p])&&-2<=params[p]&&params[p]<=1)	gal[p]=params[p]
	
	p='ThumbCrop'
	if(typeof(params[p])=='boolean')	gal.ImgSize.t.c=(params[p])?'-c':''
	
	p='ImgHeight'
	if($.isNumeric(params[p])){
		gal.ImgSize.i.real.h=params[p]
		gal.ImgSize.i.valid.h=calccanvsize(params[p],'i')
	}else{
		p=$(gal.GalleryId+gal.CanvasId+gal.ImageId).parent().innerHeight()
		gal.ImgSize.i.real.h=p
		gal.ImgSize.i.valid.h=calccanvsize(p,'i')
	}
	p='ImgWidth'
	if($.isNumeric(params[p])){
		gal.ImgSize.i.real.w=params[p]
		gal.ImgSize.i.valid.w=calccanvsize(params[p],'i')
	}else{
		p=$(gal.GalleryId+gal.CanvasId+gal.ImageId).parent().innerWidth()
		gal.ImgSize.i.real.w=p
		gal.ImgSize.i.valid.w=calccanvsize(p,'i')
	}
	p='ThumbHeight'
	if($.isNumeric(params[p])){
		gal.ImgSize.t.real.h=params[p]
		gal.ImgSize.t.valid.h=calccanvsize(params[p],'t')
	}else{
		p=$(gal.GalleryId+gal.ThumbsId+gal.ImageId).parent().innerHeight()
		gal.ImgSize.t.real.h=p
		gal.ImgSize.t.valid.h=calccanvsize(p,'t')
	}
	p='ThumbWidth'
	if($.isNumeric(params[p])){
		gal.ImgSize.t.real.w=params[p]
		gal.ImgSize.t.valid.w=calccanvsize(params[p],'t')
	}else{
		p=$(gal.GalleryId+gal.ThumbsId+gal.ImageId).parent().innerWidth()
		gal.ImgSize.t.real.w=p
		gal.ImgSize.t.valid.w=calccanvsize(p,'t')
	}
	
	p='ThumbsCapacity'
	if($.isNumeric(params[p])&&params[p]>0)	gal[p]=params[p]
	p='StartImage'
	if($.isNumeric(params[p])&&params[p]>=1)gal.IndexC=params[p]-1
	p='ThreadsThumbs'
	if($.isNumeric(params[p])&&params[p]>0)	gal[p]=params[p]
	p='ThreadsCanvas'
	if($.isNumeric(params[p])&&params[p]>0)	gal[p]=params[p]
	p='PreloadQuantityBefore'
	if($.isNumeric(params[p])&&params[p]>=0)gal.PreloadQuantity[0]=params[p]
	p='PreloadQuantityAfter'
	if($.isNumeric(params[p])&&params[p]>=0)gal.PreloadQuantity[1]=params[p]
	p='PreloadOrder'
	if($.isNumeric(params[p])&&params[p]>=0)gal[p]=params[p]+1
	
	p='TransitionTime'
	if($.isNumeric(params[p])&&params[p]>=0)gal.Transition.Time=params[p]
	p='SlideShowTime'
	if($.isNumeric(params[p])&&params[p]>=0)gal.SlideShow.Time=params[p]
	
	if(gal.SlideShow.Time<gal.Transition.Time*2)gal.SlideShow.Time=gal.Transition.Time*2
	
	p='AutoStart'
	if(typeof(params[p])=='boolean')	gal.SlideShow.Plays=params[p]
	
	if(gal.User==''){
		gal.Album='/all'
	}
	
	if($(gal.GalleryId).length==0)
		return false
	
	return true
}
//********************************************
jQuery(document).ready(function() {
	request()
	
})//end doc.ready
}//end main function
